//
//  ByTabBarDoctor.m
//  jinpuyiyuan_ios
//
//  Created by mc on 2017/12/4.
//  Copyright © 2017年 mc. All rights reserved.
//

#import "ByTabBarDoctor.h"
// view
#import "ByTabBar.h"            // 自定义tabbar

// vc
#import "ByDoctorMessageVC.h"   // 消息
#import "ByDoctorMyVC.h"        // 我的

@interface ByTabBarDoctor ()
@property (nonatomic, strong) ByTabBar *bar;

@end

@implementation ByTabBarDoctor

- (void)viewDidLoad {
    [super viewDidLoad];

    [self hideSystemTabBar];
    [self initCustomTabBar];
    [self createViewControllers];
}
#pragma mark - 安全区域改变（仅在ios11以上会调用）
- (void)viewSafeAreaInsetsDidChange {
    
    [super viewSafeAreaInsetsDidChange];
}
#pragma mark - 初始化
// 隐藏自带工具栏
- (void)hideSystemTabBar {
    
    self.tabBar.hidden = true;
}
// 创建自定义bar
- (void)initCustomTabBar {
    
    [self.view addSubview:self.bar];
    [self.bar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(49);
        if (@available(ios 11.0,*)) {
            make.left.equalTo(self.view.mas_safeAreaLayoutGuideLeft);
            make.right.equalTo(self.view.mas_safeAreaLayoutGuideRight);
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
        } else {
            make.left.equalTo(self.view);
            make.right.equalTo(self.view);
            make.bottom.equalTo(self.view);
        }
    }];
    
    self.bar.images = @[@"Common_tabbar_message",@"Common_tabbar_geren"];
    self.bar.highlightImages = @[@"Common_tabbar_message_selected",@"Common_tabbar_geren_selected"];
    self.bar.titles = @[@"消息", @"我的"];
    
    [self.bar setupUI];
}
// 创建自控制器
- (void)createViewControllers {
    
    ByDoctorMessageVC *vc1 = [[ByDoctorMessageVC alloc] init];
    ByBaseNaviController *navi1 = [[ByBaseNaviController alloc] initWithRootViewController:vc1];
    
    ByDoctorMyVC *vc2 = [[ByDoctorMyVC alloc] init];
    ByBaseNaviController *navi2 = [[ByBaseNaviController alloc] initWithRootViewController:vc2];
    
    self.viewControllers = @[navi1,navi2];
}
#pragma mark - 懒加载
- (ByTabBar *)bar {
    
    if (!_bar) {
        _bar = [[ByTabBar alloc] init];
        __weak typeof(self) wself = self;
        _bar.selectBlock = ^(NSInteger index) {
            [wself selectItemWithIndex:index];
        };
    }
    return _bar;
}


#pragma mark - 点击事件
- (void)selectItemWithIndex:(NSInteger)index {
    
    self.selectedIndex = index;
}

@end
